package net.goutalk.glcs.module.desktop.service.impl;

import com.github.yulichang.base.MPJBaseServiceImpl;
import net.goutalk.glcs.common.enums.YesOrNoEnum;
import net.goutalk.glcs.module.desktop.dto.SetActivityDto;
import net.goutalk.glcs.module.desktop.entity.DesktopHistory;
import net.goutalk.glcs.module.desktop.entity.DesktopSchema;
import net.goutalk.glcs.module.desktop.mapper.DesktopHistoryMapper;
import net.goutalk.glcs.module.desktop.mapper.DesktopSchemaMapper;
import net.goutalk.glcs.module.desktop.service.IDesktopHistoryService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tanyujie
 * @since 2023-04-13
 */
@Service
@AllArgsConstructor
public class DesktopHistoryServiceImpl extends MPJBaseServiceImpl<DesktopHistoryMapper, DesktopHistory> implements IDesktopHistoryService {

    private final DesktopSchemaMapper desktopSchemaMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean setActivity(SetActivityDto dto) {
        DesktopHistory history = getById(dto.getId());
        history.setActivityFlag(YesOrNoEnum.YES.getCode());

        DesktopSchema desktopSchema = desktopSchemaMapper.selectById(history.getSchemaId());

        desktopSchema.setJsonContent(history.getJsonContent());

        updateById(history);

        desktopSchemaMapper.updateById(desktopSchema);
        return true;
    }
}
